import 'package:flutter/material.dart';

class FutureExample extends StatefulWidget {
  @override
  _FutureExampleState createState() => _FutureExampleState();
}

class _FutureExampleState extends State<FutureExample> {
  Future<String> getFuture() {
    return Future.delayed(Duration(seconds: 3), () {
      return Future.value('Future Delay!');
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('FutureExample'),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          getFuture().timeout(Duration(seconds: 2)).then((value) {
            print(value);
          }).catchError((error) {
            print(error);
          });
        },
        child: Text('Click'),
      ),
    );
  }
}
